<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class CreateGlobalNoticeTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('global_notice', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '全局公告表']);
        $table
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('type', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => MysqlAdapter::INT_TINY, 'comment' => '1:戏剧调整 2:排期调整 3:质检报告 4:异常需求 5:成片封板 6:成片解封 7:每日报表 8:系统公告 9:QA预警'])
            ->addColumn('title', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_REGULAR, 'comment' => '公告标题'])
            ->addColumn('publisher', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 10, 'comment' => '公告发布者'])
            ->addColumn('content', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_LONG, 'comment' => '公告内容,支持富文本'])
            ->addColumn('summary', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_REGULAR, 'comment' => '公告内容摘要'])
            ->addColumn('is_top', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => MysqlAdapter::INT_TINY, 'comment' => '公告是否置顶 0:否 1:是'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => '公告其他数据'])
            ->addColumn('created_at', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '公告发布时间'])
            ->addIndex(['type', 'publisher'], ['type' => 'normal', 'name' => 'idx_type_publisher'])
            ->create();
    }

    public function down()
    {
        $this->table('global_notice')->drop()->save();
    }
}
